import Base3D from '../index'

export default class Element {
  constructor() {
    this.base3D = Base3D.getInstance()
    this.resource = this.base3D.resource
    this.camera = this.base3D.camera
    this.scene = this.base3D.scene
    this.debug = this.base3D.debug
    this.time = this.base3D.time
    this.world = this.base3D.world
    this.cannonWorld = this.base3D.cannonWorld
  }
  distory(object3D, parent) {
    parent.remove(object3D)
    const children = object3D.children
    if (!children.length) {
      return
    }
    children.forEach(({ geometry, material, childrens }) => {
      geometry.dispose()
      if (Array.isArray(material)) {
        material.forEach((m) => m.dispose())
      } else {
        material?.dispose()
      }
      if (childrens && childrens.length) {
        childrens.forEach((item) => this.distory(item, object3D))
      }
    })
  }
  update() {}
  resize() {}
}
